import com.atguigu.gmall.realtime.bean.KeywordBean;

import java.lang.reflect.Field;

/**
 * @Author lzc
 * @Date 2023/4/27 14:19
 */
public class Demo1 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Class<KeywordBean> tClass = KeywordBean.class;
        KeywordBean bean = new KeywordBean();
        bean.setStt("abc");
        
        //        Field[] fields = tClass.getFields();  // 只能获取 public 的属性
        //Field[] fields = tClass.getDeclaredFields();  //
        /*String msg = "";
        for (int i = 0; i < fields.length; i++) {
            if(i < fields.length - 1){
                msg += fields[i].getName() + ",";
            }else{
                msg += fields[i].getName();
            }
        }*/
       /* String msg = Arrays.stream(fields)
            .map(f -> f.getName())
            .collect(Collectors.joining(","));
        System.out.println(msg);*/
    
        Field stt = tClass.getDeclaredField("stt");
        // obj.stt=v 设置
        stt.setAccessible(true);  // 设置属性可访问
        //Object o = stt.get(bean);
        
        stt.set(bean, "aaaaaa");
        
        System.out.println(bean);
        
    
    }
}
